package com.zqwh.yj.sdk.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Hanker on 2015/08/25.
 */
public class SharePreferencesUtils {
    private static final String TAG = "BXW_SHARED_PREfERENCES";

    public static void writeBooleanSharedPreferences(Context context, String key, Boolean value) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public static boolean readBooleanSharedPreferences(Context context, String key) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        Boolean value = sp.getBoolean(key, false);
        return value;
    }

    public static boolean readBooleanSharedPreferences(Context context, String key, boolean defVal) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        Boolean value = sp.getBoolean(key, defVal);
        return value;
    }

    public static void writeStringSharedPreferences(Context context,String key, String value) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public static String readStringSharedPreferences(Context context,String key) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        String value = sp.getString(key, "");
        return value;
    }

    public static void writeLongSharedPreferences(Context context,String key, long value) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putLong(key, value);
        editor.commit();
    }

    public static long readLongSharedPreferences(Context context,String key) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        return sp.getLong(key, -1);
    }

    public static void writeIntSharedPreferences(Context context,String key, int value) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(key, value);
        editor.commit();
    }


    public static int readIntSharedPreferences(Context context,String key) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        return sp.getInt(key, 0);
    }

    public static int readIntSharedPreferences(Context context,String key, int defValue) {
        SharedPreferences sp = context.getSharedPreferences(TAG,
                Activity.MODE_PRIVATE);
        return sp.getInt(key, defValue);
    }

    public static void clear(Context context) {
        SharedPreferences sp = context.getSharedPreferences(TAG, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.commit();
    }
}
